package com.hmall.common.config;

import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//注册UserInfoInterceptor 拦截器，启用此拦截器,别忘记让其他微服务的application扫描此类,或者配置到spring.factories
//@Configuration //注释掉 springboot 2.x的老写法
@AutoConfiguration
@ConditionalOnClass(DispatcherServlet.class) //如果没引用MVC, 不存在DispatcherServlet 类，也就不用拦截
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());//默认拦截所有path
    }
}
